<?php
class Cl_PostManager extends WdkManager 
{
	/**
	 * 생성자
	 */
	function __construct()
	{
		parent::__construct();
		$this->dbo = Wdk::model(basename(__DIR__));
		$this->filter	= array("`p`.`post_del_flag` = 'F'");
		$this->order	= array("`p`.`post_time` DESC");
	}
	
	protected function newObj()
	{
		return Wdk::get(basename(__DIR__));
	}
	
	public function getLatest($bbs_id='', $num=5)
	{
		try 
		{
			$bbs = Wdk::get('Bbs');
			$bbs->loadById($bbs_id);
			
			$this->listsize	= $num;
			$this->page		= 1;
			$this->where	= array("`p`.`bbs_seq` = {$bbs['bbs_seq']}");
			$this->order	= array("`p`.`post_time` DESC");
			parent::load();
			return $this->lists;
		}
		catch(WException $e)
		{
			
		}
		return array();
	}
	
	public function countByBbsSeq($bbs_seq=0)
	{
		return $this->dbo->count("`p`.`bbs_seq` = {$bbs_seq}");
	}
	
	public function getLinkedByUser($post)
	{
		try
		{
			$this->listsize	= 5;
			$this->page		= 1;
			$this->where	= array("`p`.`user_seq` = {$post['user_seq']}", "`p`.`post_seq` != {$post['post_seq']}", "`p`.`post_secure_flag` = 'F'");
			$this->order	= array("`p`.`post_time` DESC");
			parent::load();
			return $this->lists;
		}
		catch(NoRecordException $e){return array();}
	}
}